jQuery(function() {
	jQuery.ajaxSetup({
		case: false,
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});

	var doc = document,
		$doc = $(doc),
		base = {
			code: false,
			realName: false,
			contact: false,
			qq: false,
			email: false,
			id: false
		};
	!function init() {
		//显示错误信息
		function showErrorMessage(node) {
			utils.errorMessage(node, "*必填");
		}
		//清除错误信息
		function clearMessage(input, node) {
			$doc.on("focus", input, function() {
				utils.clearErrMessage(node);
			});
		}

		/*验证姓名等 start*/
		$doc.on("click", ".next button", function() {
			var code = $(".code input").val(),
				realName = $(".first .real_name input").val(),
				contact = $(".first .contact input").val(),
				qq = $(".first .qq input").val(),
				email = $(".first .email input").val(),
				id = $(".first .id input").val();

			//if (!utils.empty(code)) {
			//	base.code = true;
			//} else {
			//	base.code = false;
			//	showErrorMessage($(".code_error"));
			//}

			if (!utils.empty(realName)) {
				base.realName = true;
			} else {
				base.realName = false;
				showErrorMessage($(".realName_error"));
			}

			if (!utils.empty(contact)) {
				base.contact = true;
			} else {
				base.contact = false;
				showErrorMessage($(".contact_error"));
			}

			if (!utils.empty(qq)) {
				base.qq = true;
			} else {
				base.qq = false;
				showErrorMessage($(".qq_error"));
			}

			if (!utils.empty(email)) {
				base.email = true;
			} else {
				base.email = false;
				showErrorMessage($(".email_error"));
			}

			if (!utils.empty(id)) {
				base.id = true;
			} else {
				base.id = false;
				showErrorMessage($(".id_error"));
			}

			if (base.realName &&
				base.contact &&
				base.qq &&
				base.email &&
				base.id) {

				setFacInfo();
			}
			
		});
		//提交基础信息
		function setFacInfo(){
			var cardf_id = $('#cardf_id').val();
			var cardb_id = $('#cardb_id').val();

			if(cardf_id == 0 || cardb_id == 0){
				noty({text:'请上传身份证【正】【反】面照片',type:'error',timeout:800});
			}else {
				$.ajax({
					type: "post",
					url: setFacInfoUrl,
					dataType: "json",
					data: $('#setPopInfo').serialize(),
					success: function (obj) {
						if (obj.level == 'success') {
							noty({
								text: '申请成功，请耐心等待wike工作人员审核', type: obj.level, timeout: 500,
								callback: {
									afterClose: function () {
										window.location.href = Home;
									}
								}
							});
						}
					},
					error: function (obj) {
						var datajson = obj.responseJSON;
						noty({text: datajson.message, type: datajson.level, timeout: 1000});
					}
				});
			}
		}
			//清除错误信息
		clearMessage(".real_name", $(".realName_error"));
		clearMessage(".contact", $(".contact_error"));
		clearMessage(".qq", $(".qq_error"));
		clearMessage(".email", $(".email_error"));
		clearMessage(".id", $(".id_error"));
		clearMessage(".code", $(".code_error"));
		/*验证姓名等 end*/
	}();
});